package com.wu.dao.impl;

import com.wu.bean.Comment;
import com.wu.dao.CommentDao;
import com.wu.model.CommentModel;

import java.util.List;

public class CommentDaoImpl extends BaseDao implements CommentDao {
    @Override
    public List<CommentModel> queryCommentAll() {
        String sql="SELECT c.id,u.username,c.reviewarticles,c.comments,c.time FROM COMMENT c,USER u WHERE u.id=c.reviewers  ORDER BY TIME DESC";
        return queryForList(CommentModel.class,sql);
    }

    @Override
    public List<CommentModel> queryCommentUserIdAll(int id) {
        String sql="SELECT c.id,u.username,c.reviewers,c.comments,c.time FROM COMMENT c,USER u WHERE u.id=c.reviewers AND c.reviewers=?  ORDER BY TIME DESC";
        return queryForList(CommentModel.class,sql,id);
    }

    @Override
    public List<CommentModel> queryJournalIdAll(int id) {
        String sql="SELECT c.id,u.username,c.reviewarticles,c.comments,c.time FROM COMMENT c,USER u WHERE u.id=c.reviewers AND c.reviewarticles=?  ORDER BY TIME DESC";
        return queryForList(CommentModel.class,sql,id);
    }

    @Override
    public int AddComment(Comment comment) {
        String sql="INSERT INTO COMMENT(reviewarticles,reviewers,comments,TIME)VALUES(?,?,?,?)";
        return update(sql,comment.getReviewarticles(),comment.getReviewers(),comment.getComments(),comment.getTime());
    }

    @Override
    public int DeleteComment(int id) {
        String sql="DELETE FROM COMMENT WHERE id=?";
        return  update(sql,id);
    }
}
